package actionForms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class AddContactValidationForm extends ActionForm {	
	
	private static final long serialVersionUID = 1L;
	private String contactIdTextBox = null;
	private String lastNameTextBox = null;
	private String firstNameTextBox = null;
	private String emailTextBox = null;
	
	public String getcontactIdTextBox(){
		return this.contactIdTextBox;
	}
	
	public void setcontactIdTextBox(String text){
		this.contactIdTextBox = text;
	}
	
	public String getlastNameTextBox(){
		return this.lastNameTextBox;
	}
	
	public void setlastNameTextBox(String text){
		this.lastNameTextBox = text;
	}
	
	public String getfirstNameTextBox(){
		return this.firstNameTextBox;
	}
	
	public void setfirstNameTextBox(String text){
		this.firstNameTextBox = text;
	}
	
	public String getemailTextBox(){
		return this.emailTextBox;
	}
	
	public void setemailTextBox(String text){
		this.emailTextBox = text;
	}
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		
		this.contactIdTextBox = null;
		this.lastNameTextBox = null;
		this.firstNameTextBox = null;
		this.emailTextBox = null;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 
			ActionErrors errors = new ActionErrors();
	    
			if(getcontactIdTextBox() == null || getcontactIdTextBox().length() < 1){
				errors.add("contactIdTextBox", new ActionMessage("AddContact.contactIdTextBox.error.required"));
			}			
			
			if(getlastNameTextBox() == null || getlastNameTextBox().length() < 1){
				errors.add("lastNameTextBox", new ActionMessage("AddContact.lastNameTextBox.error.required"));
			}			
			
			if(getfirstNameTextBox() == null || getfirstNameTextBox().length() < 1){
				errors.add("firstNameTextBox", new ActionMessage("AddContact.firstNameTextBox.error.required"));
			}			
			
			if(getemailTextBox() == null || getemailTextBox().length() < 1){
				errors.add("emailTextBox", new ActionMessage("AddContact.emailTextBox.error.required"));
			}			
			 
	    return errors;
	}
} 